package com.lh.controller;

import com.alibaba.fastjson.JSONObject;
import com.lh.entity.table.DeadLineNodeRecord;
import com.lh.entity.table.DeadlineNodeUpdate;
import com.lh.service.DeadLineNodeRecordService;
import com.lh.service.DeadlineNodeUpdateServer;
import com.lh.utils.Answer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/deadLineNodeRecord")
public class DeadLineNodeRecordController {
    @Autowired
    private DeadLineNodeRecordService deadLineNodeRecordService;
    @Autowired
    private DeadlineNodeUpdateServer deadlineNodeUpdateServer;


    @RequestMapping("/addDeadLineNodeRecord")
    public Answer<Object> addCompanyData(@RequestBody DeadLineNodeRecord deadLineNodeRecord) {
        return deadLineNodeRecordService.addDeadLineNodeRecord(deadLineNodeRecord);
    }


    /**
     * 申请更新进度
     * @param deadLineNodeRecord
     * @return
     */
    @RequestMapping("/updateDeadNodeRecord")
    public Answer<Object> updateCompanyData(@RequestBody DeadlineNodeUpdate deadLineNodeRecord) {
        int result = deadlineNodeUpdateServer.submitProgressUpdate(deadLineNodeRecord);
        if (result == 1){
            return Answer.ok("提交成功");
        }
        return Answer.error("提交失败");
    }

    @RequestMapping("/approvalDeadNodeRecord")
    public Answer<Object> approvalDeadNodeRecord(@RequestBody DeadlineNodeUpdate deadLineNodeRecord) {
        int result = deadlineNodeUpdateServer.handleNodeUpdateApproval(
                deadLineNodeRecord.getId(),
                deadLineNodeRecord.getNodeId(),
                deadLineNodeRecord.getApprovalStatus(),
                deadLineNodeRecord.getApprovalReason()
        );
        if (result == 1){
            return Answer.ok("审核成功");
        }
        return Answer.error("审核失败");
    }



    @RequestMapping("/updateDeadLineNodeRecord")
    public Answer<Object> updateCompanyData(@RequestBody DeadLineNodeRecord deadLineNodeRecord) {
        return deadLineNodeRecordService.updateDeadLineNodeRecord(deadLineNodeRecord);
    }

    @RequestMapping("/deleteDeadLineNodeRecord")
    public Answer<Object> deleteCompanyData(@RequestBody DeadLineNodeRecord deadLineNodeRecord) {
        return deadLineNodeRecordService.deleteDeadLineNodeRecord(deadLineNodeRecord);
    }

    @RequestMapping("/queryDeadLineNodeRecordList")
    public Answer<Object> queryCompanyDataList(@RequestBody DeadLineNodeRecord deadLineNodeRecord) {
        return deadLineNodeRecordService.queryDeadLineNodeRecordList(deadLineNodeRecord);
    }

    @RequestMapping("/queryDeadLineNodeRecordPage")
    public Answer<Object> queryCompanyDataPage(@RequestBody JSONObject reqJson) {
        return deadLineNodeRecordService.queryDeadLineNodeRecordPage(reqJson);
    }
}
